package com.ld.poetry.vo.upload;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;

public enum FileSizeUnitEnums {
    BYTE(1L, Arrays.asList("b","byte")),
    KB(1024L,Arrays.asList("k","kb")),
    MB(1024 * 1024L,Arrays.asList("m","mb")),
    GB(1024 * 1024 * 1024L,Arrays.asList("g","gb"));

    @Getter
    private final Long singleSize;

    @Getter
    private final List<String> unitList;

    public static final long DEFAULT_MAX_SIZE = 52428800;

    FileSizeUnitEnums(Long singleSize, List<String> unitList){
        this.singleSize = singleSize;
        this.unitList = unitList;
    }

    public static Long getMaxSizeLong(String unit,Long unitSize){
        return Arrays
                .stream(FileSizeUnitEnums.values())
                .filter(sizeUnit -> sizeUnit.getUnitList().contains(unit.toLowerCase()))
                .mapToLong(sizeUnit -> sizeUnit.getSingleSize() * unitSize)
                .findAny()
                .orElse(DEFAULT_MAX_SIZE);
    }
}
